package com.maixy.redisdemo.service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.maixy.redisdemo.entity.RedisUser;
import com.maixy.redisdemo.mapper.RedisUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName RedisUserService
 * @Description TODO
 * @Date 2021/5/16 19:17
 * @Author maixy
 */
@Service
@DS("master")
public class RedisUserService extends BaseMPlusService<RedisUser, Long>{

    @Resource
    private RedisUserMapper redisUserMapper;


    protected RedisUserService(RedisUserMapper redisUserMapper) {
        super(RedisUser.class, redisUserMapper);
        this.redisUserMapper = redisUserMapper;
    }


    @DS("slave")
    //@DS可以注解在方法上或类上，同时存在就近原则 方法上注解 优先于 类上注解。
    public RedisUser find(Long redisUserId) {
        return findById(redisUserId);
    }

    public RedisUser insert1() {
        RedisUser redisUser = new RedisUser();
        redisUser.setUsername("23123123");
        redisUser.setPassword("23123123");
        return create(redisUser);
    }
}
